package org.example.controller;

import org.example.pojo.User;
import org.example.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("user")
public class Usercontroller {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("login")
    public User login(User u){

        return userService.login(u);
    }
    @RequestMapping("add")
    public int add(User u){
        return userService.add(u);
    }
    @RequestMapping("upd")
    public User upd(User u,String passwordx){
        return userService.upd(u,passwordx);
    }
    @RequestMapping("update")
    public int update(int id,String password){
        return userService.update(id,password);
    }

    //上传照片
    @PostMapping("pian")
    public String pian(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String poth="C:\\Users\\Administrator\\Desktop\\项目\\digital-interviewer-vue\\src\\photo";

        File f=new File(poth,originalFilename);
        file.transferTo(f);

        String url="http://localhost:8992/user/photo/"+originalFilename;
        System.err.println(url);
        return url;
    }
}
